Apache Wink : 5.7 Handler Chain - Runtime Extension
This page last changed on Oct 12, 2009 by bluk.
Handler Chain - Runtime ExtensionThe Apache Wink runtime utilizes three Handler Chains for the complete processing of a request: Request chain, Response chain and Error chain. A handler receives a MessageContext instance for accessing and manipulating the current request information and a HandlerChain instance for advancing the chain. It is the responsibility of the handler to pass control to the next handler on the chain by invoking the doChain() method on the HandlerChain instance. A handler may call the doChain() method several times if needed, so handlers are required to consider the possibility they will be invoked more than once for the same request. The implementation of separate chains provides the ability to move up and down one chain before moving on to the next chain. This is particularly useful for the implementation of the JAX-RS resource-method search algorithm that includes invoking sub-resource locators, and implementing the Continued Search mode. HandlersThere are two types of handlers:
Message ContextThe MessageContext allows the following: Request Handler ChainThe Request Handler Chain is responsible for processing a request according to the JAX-RS specification by accepting the request, searching for the resource method to invoke, de-serializing the request entity and finally for invoking the resource method. It is responsible for invoking sub-resource locators by moving up and down the chain as needed. A Request handler is a class that implements the org.apache.wink.server.handlers.RequestHandler interface. System Request HandlersThe following is a list of system handlers comprising the request handler chain in the order that they appear in the chain.
User Request HandlersUser request handlers are inserted before the InvokeMethodHandler handler.
Response Handler ChainThe Response Handler Chain is responsible for handling the object returned from invoking a resource method or sub-resource method according to the JAX-RS specification. It is responsible for determining the response status code, selecting the response media type and for serializing the response entity. System Response HandlersThe following is a list of system handlers comprising the response handler chain in the order that they appear in the chain.
User Response HandlersUser response handlers are inserted before the FlushResultHandler handler. Apache Wink initializes the user response handler chain with the CheckLocationHeaderHandler handler that verifies that the "Location" response header is present on a response when there is a status code that requires it, for example, status code: 201.
Error Handler ChainThe Error Handler Chain is responsible for handling all of the exceptions that are thrown during the invocation of the Request and Response handler chains, according to the JAX-RS specification for handling exceptions. It is responsible for determining the response status code, selecting the response media type and for serializing the response entity. An Error handler is a class that implements the org.apache.wink.server.handlers.ResponseHandler interface. System Error HandlersThe following is a list of system handlers comprising the error handler chain in the order that they appear in the chain. Error Handlers
User Error HandlersUser error handlers are inserted before the FlushResultHandler handler.
Request ProcessingThe following details how the Apache Wink runtime performs request processing:
If at any time during the execution of a Request or Response chain an exception is thrown, catch the exception, wrap it in a new MessageContext instance and invoke the Error chain to produce an appropriate response. |
Document generated by Confluence on Nov 11, 2009 06:57 |